/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package im.imrobots.m.root;

import im.imrobots.IMRobots;
import im.imrobots._face.IMessage;
import im.imrobots._face.IService;
import im.imrobots._face.ISession;
import im.imrobots._face.IStatus;

/**
 *
 * @author yihaodian
 */
public class Root implements IService
{
    public Root()
    {
    }

    @Override
    public void doInit(ISession session, IMessage message)
    {
    }

    @Override
    public void doHelp(ISession session, IMessage message)
    {
    }

    @Override
    public void doDeal(ISession session, IMessage message)
    {
        String msg = message.getContent();
        String tmp = msg.toLowerCase();
        if ("exit".equals(tmp))
        {
            session.send("再见……");
            IMRobots.exit(0);
        }

        if (tmp.indexOf("step ") == 0)
        {
            String[] arr = tmp.toLowerCase().split(" ");
            if (arr.length < 3)
            {
                return;
            }

            tmp = arr[2];
            if ("online".equals(tmp))
            {
                IMRobots.step(arr[1], IStatus.LINE);
                return;
            }
            if ("offline".equals(tmp))
            {
                IMRobots.step(arr[1], IStatus.DOWN);
            }
            return;
        }
    }
}
